package com.sms.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sms.dao.INotifyPhoneDAO;
import com.sms.po.NotifyPhone;
/**
 * @author 20111006 by meng.xf
 */
public class NotifyPhoneDAO extends HibernateDaoSupport implements INotifyPhoneDAO {
	private static final Log log = LogFactory.getLog(NotifyPhoneDAO.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<NotifyPhone> showAllNotifyPhone() {
		log.debug("finding all NotifyPhone instances");
		try{
			return super.getHibernateTemplate().find("from NotifyPhone");
		}catch(RuntimeException e){
			log.debug("finding all failed:",e);
			throw e;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<NotifyPhone> showAllNotifyPhoneByPage(int start,int limit) {
		log.debug("finding all NotifyPhone by pages");
		try{
			return super.getHibernateTemplate().findByCriteria(
					DetachedCriteria.forClass(NotifyPhone.class), start, limit);
		}catch(RuntimeException e){
			log.debug("finding all NotifyPhone failed:",e);
			throw e;
		}
	}

	@Override
	public int getAllNotifyPhoneCount() {
		return this.showAllNotifyPhone().size();
	}

	@Override
	public boolean addNotifyPhone(NotifyPhone bl) {
		log.debug("add NotifyPhone instance...");
		try{
			
			this.getHibernateTemplate().save(bl);
			return true;
		}catch(RuntimeException e){
			log.debug("add NotifyPhone instance failed:",e);
			throw e;
		}
	}

	@Override
	public boolean removeNotifyPhone(NotifyPhone bl) {
		log.debug("remove NotifyPhone instance...");
		try{
			
			this.getHibernateTemplate().delete(bl);
			return true;
		}catch(RuntimeException e){
			log.debug("remove NotifyPhone instance failed:",e);
			throw e;
		}
	}

	@Override
	public boolean updateNotifyPhone(NotifyPhone bl) {
		log.debug("update NotifyPhone instance...");
		try{
			this.getHibernateTemplate().update(bl);
			return true;
		}catch(RuntimeException e){
			log.debug("update NotifyPhone instance failed:",e);
			throw e;
		}
	}

}
